home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
digex104.zip
/
DIGEXT.C
next >
Wrap
C/C++ Source or Header
|
1991-08-15
|
12KB
|
382 lines
/*
digext.c
by
Alvin Koh
isakoh@zpcp53.att.com
27 June 1991
(with minor, approved Toad Hall Tweaks)
(and Newt Hall Tweaks (tm), too! :-) )
For extracting digest issues from files (including the INFO-ZIP
.sma files recently posted). Files may contain more than one
digest issue. Digests issues are located using the strings defined
in the lookup table below.
Digest issue files created have names like IZIP091.199.
Notes:
1. Carriage returns (^M) are not removed from digests. For
non-MSDOS users, use flip to remove them.
2. If a digest issue file already exists, it is not overwritten.
3. Right now, digext recognizes the digests listed in the lookup
table. Add new digest info if you need to.
4. One added benefit of digext is that you can use it to rename
your existing digests.
Copyright (C) 1991, Alvin Koh. All Rights Reserved.
Permission is granted to any individual or institution to use, copy, or
redistribute this software so long as it is not sold for profit,
provided this copyright notice is retained.
Feel free to enhance this program, but do send me a copy of
your modifications.
History:
~~~~~~~~
1.01 27 June 1991 Alvin Koh (isakoh@zpcp53.att.com)
Creation...
1.02 28 June 1991 David Kirschbaum (kirsch@usasoc.soc.mil)
Added include files for compilation under Turbo C.
1.03 6 July 1991 Alvin Koh (isakoh@zpcp53.att.com)
Added lookup table to support various digest types/formats.
I have only tested digext with INFO-ZIP and UNIX-WIZARDS digests
so far, as these are the 2 digests I subscribe to currently.
Please send me your bug reports, enhancements and new formats.
1.04 10 July 1991 Alvin Koh (isakoh@zpcp53.att.com)
Changed the various *unwieldy* sscanf formats to short and
more manageable ones. Volume and Issue variable changed from
char[80] to int.
1.04a 13 August 1991 Cave Newt (roelofs@amelia.nas.nasa.gov)
Tweaks for VMS/VAXC compilation (didn't like void main; return
status must be zero or else interpreted strangely; added wildcard
code). Tested a little bit on INFO-ZIP digests.
*/
#include <stdio.h>
#include <string.h>
#define VERSION "1.04a"
#define DATE "13 August 1991"
#ifdef __STDC__
#include <process.h> /* exit() */
#include <io.h> /* access() */
#endif
#ifdef VMS
# include <rms.h>
# include <ssdef.h>
# include <descrip.h>
typedef struct direct {
int d_wild; /* flag for wildcard vs. non-wild */
struct FAB fab;
struct NAM nam;
char d_qualwildname[NAM$C_MAXRSS + 1];
char d_name[NAM$C_MAXRSS + 1];
} DIR;
int _vms_findfirst(char *, DIR *);
int _vms_findnext(DIR *);
#endif /* VMS */
typedef struct INFO_TABLE_T INFO_TABLE;
struct INFO_TABLE_T {
char *DIGEST_BEGIN; /* start of digest */
char *DIGEST_END; /* end of digest */
char *DIGEST_FMT; /* format of digest name */
char *DIGEST_SCAN; /* scanf format to extract volume/issue number */
} info_table[] = {
"INFO-ZIP Digest", /* tested by Alvin Koh */
"End of INFO-ZIP Digest",
"IZIP%03d.%03d",
"%*[^V] %*s %d %*c %*s %d",
"Info-IBMPC Digest", /* tested by Alvin Koh */
"End of Info-IBMPC Digest",
"IIBM%03d.%03d",
"%*[^V] %*s %d %*c %*s %d",
"INFO-C Digest",
"End of Info-C Digest",
"IC%03d.%03d",
"%*[^V] %*s %d %*c %*s %d",
"INFO-WIZARD Digest",
"End of Info-WIZARD Digest",
"IWIZ%03d.%03d",
"%*[^V] %*s %d %*c %*s %d",
"Info-Kermit Digest", /* tested by Alvin Koh */
"End of Info-Kermit Digest",
"IKER%03d.%03d",
"%*[^V] %*s %d %*c %*s %d",
"UNIX-WIZARDS Digest", /* tested by Alvin Koh */
"End of UNIX-WIZARDS Digest",
"UWIZ%03d.%03d",
"%*[^V] %*c %d %*c %d",
"VIRUS-L Digest", /* tested by Alvin Koh */
"End of VIRUS-L Digest",
"VL%03d.%03d",
"VIRUS-L %*[^V] %*s %d %*c %*s %d",
/* add new info after this line */
/* add new info before this line */
NULL, NULL, NULL, NULL
};
#ifdef VAXC
int main(int argc, char *argv[])
#else /* !VAXC */
void main(argc, argv)
int argc;
char *argv[];
#endif /* ?VAXC */
{
FILE *fi; /* digest source descriptor */
FILE *fo; /* digest file descriptor */
char s[BUFSIZ]; /* line of text from digest source */
int Volume; /* digest volume number */
int Issue; /* digest issue number */
char digest[80]; /* name of digest file */
int in_digest = 0; /* 'in digest' flag */
int i;
INFO_TABLE *it; /* ptr for searching info table */
char digest_id[80]; /* storage for digest name */
char keyword[80]; /* use for locate 'Digest' keyword */
#ifdef VMS
DIR d; /* struct direct for VMS wildcards */
#endif /* VMS */
if (argc == 1) {
printf("digext - The Digest Extractor v%s (%s)\n", VERSION, DATE);
printf("(C)Copyright 1991, Alvin Koh. All Rights Reserved\n\n");
printf("Usage: digext file [ file ... ]\n");
exit(0);
}
for (i = 1; i < argc; i++) {
/* open raw digest source */
#ifdef VMS
_vms_findfirst(argv[i], &d);
while (_vms_findnext(&d) == 0) {
if ((fi = fopen(d.d_name, "r")) == NULL) {
#else /* !VMS */
if ((fi = fopen(argv[i], "r")) == NULL) {
#endif /* ?VMS */
printf("Can't open %s\n", argv[i]);
continue;
}
#ifdef VMS
printf("Processing %s ...\n", d.d_name);
#else /* !VMS */
printf("Processing %s...\n", argv[i]);
#endif /* ?VMS */
/* look for start of digest issue */
while (fgets(s, BUFSIZ, fi) != NULL) {
/* found it */
if (!in_digest) {
/* look for 'Digest' keyword */
sscanf(s, "%s %s", digest_id, keyword);
if (strcmp(keyword, "Digest") != 0)
continue;
/* clear keyword to prevent re-loop */
keyword[0] = '\0';
/* look up info table */
it = info_table;
while (it->DIGEST_BEGIN &&
strncmp(it->DIGEST_BEGIN, digest_id, strlen(digest_id)))
it++;
if (it->DIGEST_BEGIN == NULL) {
printf("No info available for %s Digest\n", digest_id);
continue;
}
/* scan for volume/issue number */
sscanf(s, it->DIGEST_SCAN, &Volume, &Issue);
/* form name of digest issue */
sprintf(digest, it->DIGEST_FMT, Volume, Issue);
/* if already exists, skip */
if (access(digest, 00) == 0) {
printf("\t%s already exists\n", digest);
continue;
}
printf("\tExtracting %s Digest Volume %d Issue %d\n", digest_id, Volume, Issue);
/* create issue file */
if ((fo = fopen(digest, "w")) == NULL) {
printf("Can't create %s\n", digest);
#ifdef VMS
exit(0); /* VMS interprets exit statuses annoyingly */
#else /* !VMS */
exit(1);
#endif /* ?VMS */
}
/* set 'in digest' flag */
in_digest = 1;
}
/* found end of digest */
if (in_digest && !strncmp(s, it->DIGEST_END, strlen(it->DIGEST_END))) {
/* reset flag */
in_digest = 0;
/* print ending lines */
fprintf(fo, "%s", s);